/*
 * ========================================================
 * Copyright(c) 2014 杭州偶尔科技-版权所有
 * ========================================================
 * 本软件由杭州偶尔科技所有, 未经书面许可, 任何单位和个人不得以
 * 任何形式复制代码的部分或全部, 并以任何形式传播。
 * 公司网址
 * 
 * 			http://www.kkkd.com/
 * 
 * ========================================================
 */
package com.ouertech.android.agm.lib.ui.base.defaults.activity;

import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;

import com.ouertech.android.agm.lib.ui.R;
import com.ouertech.android.agm.lib.ui.base.BaseUIActivity;
import com.ouertech.android.agm.lib.ui.base.BaseUIFragment;
import com.ouertech.android.agm.lib.ui.base.UIOptions;

/**
 * @author : Zhenshui.Xia
 * @date : 2015/10/15.
 * @desc : 全屏界面, 通过声明清单里的activity theme属性 android:theme="@style/res_theme_fullscreen_app"
 *         体验更佳
 */
public abstract class BaseFullActivity extends BaseUIActivity{

    @Override
    protected long initOptions() {
        return UIOptions.UI_OPTIONS_SCREEN_FULL;
    }

    /**
     * 获取内容布局视图的根ID
     */
    public int getContentId() {
        return R.id.base_id_content_root;
    }

    /**
     * 添加片段
     * @param fragmentClzz
     */
    public void addFragment(Class<? extends BaseUIFragment> fragmentClzz) {
        addFragment(fragmentClzz, null);
    }

    /**
     * 添加片段
     * @param fragmentClzz
     * @param bundle
     */
    public void addFragment(Class<? extends BaseUIFragment> fragmentClzz, Bundle bundle) {
        FragmentManager fm = getSupportFragmentManager();
        FragmentTransaction ft = fm.beginTransaction();

        if (fm.getFragments() != null) {
            ft.addToBackStack(null);
        }

        ft.setCustomAnimations(R.anim.res_translate_left_in,
                R.anim.res_translate_left_out,
                R.anim.res_translate_right_in,
                R.anim.res_translate_right_out);

        try {
            BaseUIFragment fragment = (BaseUIFragment)fragmentClzz.newInstance();
            if(bundle != null) {
                fragment.setArguments(bundle);
            }

            ft.replace(getContentId(), fragment).commit();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }

}
